package com.yu.crm.controller;

import com.yu.crm.domain.pojo.CrmLogin;
import com.yu.crm.domain.pojo.CrmUser;
import com.yu.crm.service.CrmLoginService;
import com.yxzz.common.BaseResponse;

import com.yxzz.common.helper.valid.ValidatorHelpers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.HashMap;
import java.util.Map;

/**
 * 模块名称：
 * 功能说明：
 *
 * @Author: bin-donnie
 * @Date: 2019-07-29 16:37
 */

@Api(tags = "CRM登录")
@RestController
@RequestMapping(value = "/crm-login")
public class CrmLoginController {

    @Autowired
    CrmLoginService loginService;


    @ApiOperation(value = "注册")
    @PostMapping(value = "/registry")
    public void registry(@RequestBody CrmLogin entity){
        loginService.registry(entity);
    }

    @ApiOperation(value = "登录")
    @PostMapping(value = "/login")
    public CrmUser login(@RequestBody CrmLogin entity){
        return loginService.login(entity);
    }

    @ApiOperation(value = "退出")
    @PostMapping(value = "/logout")
    public void logout(String loginToken){
        loginService.logout(loginToken);
    }

    @ApiOperation(value = "检查手机号是否已注册")
    @PostMapping(value = "/is-exist-phone")
    public BaseResponse<Boolean> isExistPhone(String phone){
        return loginService.isExistPhone(phone);
    }

    @ApiOperation(value = "获取图片验证码")
    @GetMapping(value = "/request-image-code")
    public void requestImageCode(HttpServletRequest request, HttpServletResponse response){
        loginService.requestImageCode(request, response);
    }

    @ApiOperation(value = "验证图片验证码")
    @PostMapping(value = "/verify-image-code")
    public Boolean verifyImageCode(String verifyId, String code) {
        return loginService.verifyImageCode(verifyId, code);
    }

    @ApiOperation(value = "请求短信验证码")
    @PostMapping(value = "/request-sms-code")
    public Boolean requestSmsCode(String phone){
        return loginService.requestSmsCode(phone);
    }

    @ApiOperation(value = "验证短信验证码")
    @PostMapping(value = "/verify-sms-code")
    public boolean verifySmsCode(String phone, String code) {
        return loginService.verifySmsCode(phone, code);
    }





}
